import { ApiProperty } from "@nestjs/swagger";
import { Exclude } from "class-transformer";
import { Entity, Column, ManyToMany, Relation } from "typeorm";
import { CommonEntity } from "./common.entity";
import { RoleEntity } from "./role.entity";

@Entity({ name: "role_permission" })
export class PermissionEntity extends CommonEntity {
    @ApiProperty({ description: "权限名称" })
    @Column()
    name: string;

    @ApiProperty({ description: "权限描述" })
    @Column()
    description: string;

    @ApiProperty({ description: "权限代码" })
    @Column({ unique: true })
    code: string;

    @Exclude()
    @ManyToMany((type) => RoleEntity, (role) => role.permissions, {
        onDelete: "CASCADE",
    })
    roles: Relation<RoleEntity[]>;
}
